Merge "Do not unauthenticate if autocreation fails due to a race"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 18 Feb 2016 16:51:52 +0000 (16:51 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 18 Feb 2016 16:51:52 +0000 (16:51 +0000)
includes/EditPage.php
includes/Title.php
includes/db/Database.php
includes/libs/CSSMin.php
tests/phpunit/includes/libs/CSSMinTest.php

index 5ebb44a..82fcdcf 100644 (file)
@@ -1420,6 +1420,11 @@ class EditPage {
                        }
                }
 
+               // "wpExtraQueryRedirect" is a hidden input to modify
+               // after save URL and is not used by actual edit form
+               $request = RequestContext::getMain()->getRequest();
+               $extraQueryRedirect = $request->getVal( 'wpExtraQueryRedirect' );
+
                switch ( $status->value ) {
                        case self::AS_HOOK_ERROR_EXPECTED:
                        case self::AS_CONTENT_TOO_BIG:
@@ -1443,6 +1448,13 @@ class EditPage {
 
                        case self::AS_SUCCESS_NEW_ARTICLE:
                                $query = $resultDetails['redirect'] ? 'redirect=no' : '';
+                               if ( $extraQueryRedirect ) {
+                                       if ( $query === '' ) {
+                                               $query = $extraQueryRedirect;
+                                       } else {
+                                               $query = $query . '&' . $extraQueryRedirect;
+                                       }
+                               }
                                $anchor = isset( $resultDetails['sectionanchor'] ) ? $resultDetails['sectionanchor'] : '';
                                $wgOut->redirect( $this->mTitle->getFullURL( $query ) . $anchor );
                                return false;
@@ -1464,6 +1476,14 @@ class EditPage {
                                                $extraQuery = 'redirect=no&' . $extraQuery;
                                        }
                                }
+                               if ( $extraQueryRedirect ) {
+                                       if ( $extraQuery === '' ) {
+                                               $extraQuery = $extraQueryRedirect;
+                                       } else {
+                                               $extraQuery = $extraQuery . '&' . $extraQueryRedirect;
+                                       }
+                               }
+
                                $wgOut->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor );
                                return false;
 
index 38ee2ee..90ac89c 100644 (file)
@@ -3434,7 +3434,7 @@ class Title implements LinkTarget {
         * WARNING: do not use this function on arbitrary user-supplied titles!
         * On heavily-used templates it will max out the memory.
         *
-        * @param array $options May be FOR UPDATE
+        * @param array $options Query option to Database::select()
         * @return Title[] Array of Title the Title objects linking here
         */
        public function getTemplateLinksTo( $options = [] ) {
@@ -3448,7 +3448,7 @@ class Title implements LinkTarget {
         * WARNING: do not use this function on arbitrary user-supplied titles!
         * On heavily-used templates it will max out the memory.
         *
-        * @param array $options May be FOR UPDATE
+        * @param array $options Query option to Database::select()
         * @param string $table Table name
         * @param string $prefix Fields prefix
         * @return array Array of Title objects linking here
@@ -3461,11 +3461,7 @@ class Title implements LinkTarget {
                        return [];
                }
 
-               if ( count( $options ) > 0 ) {
-                       $db = wfGetDB( DB_MASTER );
-               } else {
-                       $db = wfGetDB( DB_SLAVE );
-               }
+               $db = wfGetDB( DB_SLAVE );
 
                $blNamespace = "{$prefix}_namespace";
                $blTitle = "{$prefix}_title";
index d741b2f..351d438 100644 (file)
@@ -1069,7 +1069,9 @@ abstract class DatabaseBase implements IDatabase {
                $table, $var, $cond = '', $fname = __METHOD__, $options = [], $join_conds = []
        ) {
                if ( $var === '*' ) { // sanity
-                       throw new DBUnexpectedError( $this, "Cannot use a * field: got '$var'" );
+                       throw new DBUnexpectedError( $this, "Cannot use a * field" );
+               } elseif ( !is_string( $var ) ) { // sanity
+                       throw new DBUnexpectedError( $this, "Cannot use an array of fields" );
                }
 
                if ( !is_array( $options ) ) {
index 5f4dda9..ece29e8 100644 (file)
@@ -349,7 +349,7 @@ class CSSMin {
                                                        $url = $match['file'] . $match['query'];
                                                        $file = $local . $match['file'];
                                                        if (
-                                                               !CSSMin::isRemoteUrl( $url ) && !CSSMin::isLocalUrl( $url )
+                                                               !self::isRemoteUrl( $url ) && !self::isLocalUrl( $url )
                                                                && file_exists( $file )
                                                        ) {
                                                                $mimeTypes[ CSSMin::getMimeType( $file ) ] = true;
@@ -391,11 +391,10 @@ class CSSMin {
        /**
         * Is this CSS rule referencing a remote URL?
         *
-        * @private Until we require PHP 5.5 and we can access self:: from closures.
         * @param string $maybeUrl
         * @return bool
         */
-       public static function isRemoteUrl( $maybeUrl ) {
+       protected static function isRemoteUrl( $maybeUrl ) {
                if ( substr( $maybeUrl, 0, 2 ) === '//' || parse_url( $maybeUrl, PHP_URL_SCHEME ) ) {
                        return true;
                }
@@ -405,11 +404,10 @@ class CSSMin {
        /**
         * Is this CSS rule referencing a local URL?
         *
-        * @private Until we require PHP 5.5 and we can access self:: from closures.
         * @param string $maybeUrl
         * @return bool
         */
-       public static function isLocalUrl( $maybeUrl ) {
+       protected static function isLocalUrl( $maybeUrl ) {
                if ( $maybeUrl !== '' && $maybeUrl[0] === '/' && !self::isRemoteUrl( $maybeUrl ) ) {
                        return true;
                }
index 6c0a923..8902ecd 100644 (file)
@@ -155,7 +155,7 @@ class CSSMinTest extends MediaWikiTestCase {
         * @cover CSSMin::isRemoteUrl
         */
        public function testIsRemoteUrl( $expect, $url ) {
-               $this->assertEquals( CSSMin::isRemoteUrl( $url ), $expect );
+               $this->assertEquals( CSSMinTestable::isRemoteUrl( $url ), $expect );
        }
 
        public static function provideIsLocalUrls() {
@@ -172,7 +172,7 @@ class CSSMinTest extends MediaWikiTestCase {
         * @cover CSSMin::isLocalUrl
         */
        public function testIsLocalUrl( $expect, $url ) {
-               $this->assertEquals( CSSMin::isLocalUrl( $url ), $expect );
+               $this->assertEquals( CSSMinTestable::isLocalUrl( $url ), $expect );
        }
 
        public static function provideRemapRemappingCases() {
@@ -443,3 +443,13 @@ class CSSMinTest extends MediaWikiTestCase {
                ];
        }
 }
+
+class CSSMinTestable extends CSSMin {
+       // Make some protected methods public
+       public static function isRemoteUrl( $maybeUrl ) {
+               return parent::isRemoteUrl( $maybeUrl );
+       }
+       public static function isLocalUrl( $maybeUrl ) {
+               return parent::isLocalUrl( $maybeUrl );
+       }
+}